Option Explicit On

'Copyright (c) 2007-2010, William Severance, Jr., WESNet Designs
'All rights reserved.

'Redistribution and use in source and binary forms, with or without modification, are permitted
'provided that the following conditions are met:

'Redistributions of source code must retain the above copyright notice, this list of conditions
'and the following disclaimer.

'Redistributions in binary form must reproduce the above copyright notice, this list of conditions
'and the following disclaimer in the documentation and/or other materials provided with the distribution.

'Neither the name of William Severance, Jr. or WESNet Designs may be used to endorse or promote
'products derived from this software without specific prior written permission.

'Disclaimer: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
'            OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
'            AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE
'            FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
'            LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
'            INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
'            OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
'            IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'Although I will try to answer questions regarding the installation and use of this software when
'such questions are submitted via e-mail to the below address, no promise of further
'support or enhancement is made nor should be assumed.

'Developer Contact Information:
'     William Severance, Jr.
'     WESNet Designs
'     679 Upper Ridge Road
'     Bridgton, ME 04009
'     Phone: 207-647-9375
'     E-Mail: bill@wesnetdesigns.com
'     Website: www.wesnetdesigns.com

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Namespace WESNet.DNN.Modules.EPrayer

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' SQL Server implementation of the abstract DataProvider class
    ''' </summary>
    ''' <remarks>
    ''' Written By Bill Severance, WESNet Designs - www.wesnetdesigns.com
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class SqlDataProvider

        Inherits DataProvider

#Region "Private Members"

        Private Const ProviderType As String = "data"
        Private Const CompanyQualifier As String = "WESNet_"
        Private Const ModuleQualifier As String = "EPrayer_"

        Private _providerConfiguration As Framework.Providers.ProviderConfiguration = Framework.Providers.ProviderConfiguration.GetProviderConfiguration(ProviderType)
        Private _connectionString As String
        Private _providerPath As String
        Private _objectQualifier As String
        Private _databaseOwner As String

#End Region

#Region "Constructors"

        Public Sub New()

            ' Read the configuration specific information for this provider
            Dim objProvider As Framework.Providers.Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Framework.Providers.Provider)

            ' This code handles getting the connection string from either the connectionString / appsetting section and uses the connectionstring section by default if it exists.  
            ' Get Connection string from web.config
            _connectionString = DotNetNuke.Common.Utilities.Config.GetConnectionString()

            ' If above funtion does not return anything then connectionString must be set in the dataprovider section.
            If _connectionString = "" Then
                ' Use connection string specified in provider
                _connectionString = objProvider.Attributes("connectionString")
            End If

            _providerPath = objProvider.Attributes("providerPath")

            _objectQualifier = objProvider.Attributes("objectQualifier")
            If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
                _objectQualifier += "_"
            End If

            _databaseOwner = objProvider.Attributes("databaseOwner")
            If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
                _databaseOwner += "."
            End If

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property ConnectionString() As String
            Get
                Return _connectionString
            End Get
        End Property

        Public ReadOnly Property ProviderPath() As String
            Get
                Return _providerPath
            End Get
        End Property

        Public ReadOnly Property ObjectQualifier() As String
            Get
                Return _objectQualifier
            End Get
        End Property

        Public ReadOnly Property DatabaseOwner() As String
            Get
                Return _databaseOwner
            End Get
        End Property

#End Region

#Region "Private Methods"

        Private Function GetFullyQualifiedName(ByVal name As String) As String
            Return DatabaseOwner & ObjectQualifier & CompanyQualifier & ModuleQualifier & name
        End Function

        Private Function GetNull(ByVal Field As Object) As Object
            Return DotNetNuke.Common.Utilities.Null.GetNull(Field, DBNull.Value)
        End Function

#End Region

#Region "Public Methods"

#Region "Categories"
        Public Overrides Function GetCategories(ByVal ModuleID As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetCategories"), Null.GetNull(ModuleID, DBNull.Value)), IDataReader)
        End Function

        Public Overrides Function GetCategory(ByVal CategoryID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetCategory"), CategoryID), IDataReader)
        End Function

        Public Overrides Sub AddCategory(ByVal objCategory As CategoryInfo)
            With objCategory
                .CategoryID = CInt(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddCategory"), Null.GetNull(.ModuleID, DBNull.Value), .Category, .ViewOrder))
            End With
        End Sub

        Public Overrides Sub DeleteCategory(ByVal CategoryID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteCategory"), CategoryID)
        End Sub

        Public Overrides Sub UpdateCategory(ByVal objCategory As CategoryInfo)
            With objCategory
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateCategory"), Null.GetNull(.ModuleID, DBNull.Value), .CategoryID, .Category, .ViewOrder)
            End With
        End Sub
#End Region

#Region "Stati"
        Public Overrides Function GetStati() As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetStati")), IDataReader)
        End Function

        Public Overrides Function GetStatus(ByVal StatusID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetStatus"), StatusID), IDataReader)
        End Function

        Public Overrides Sub AddStatus(ByVal objStatus As StatusInfo)
            With objStatus
                .StatusID = CInt(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddStatus"), .Status, .ViewOrder))
            End With
        End Sub

        Public Overrides Sub DeleteStatus(ByVal StatusID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteStatus"), StatusID)
        End Sub

        Public Overrides Sub UpdateStatus(ByVal objStatus As StatusInfo)
            With objStatus
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateStatus"), .StatusID, .Status, .ViewOrder)
            End With
        End Sub
#End Region

#Region "Relationships"
        Public Overrides Function GetRelationships() As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetRelationships")), IDataReader)
        End Function

        Public Overrides Function GetRelationship(ByVal RelationshipID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetRelationship"), RelationshipID), IDataReader)
        End Function

        Public Overrides Sub AddRelationship(ByVal objRelationship As RelationshipInfo)
            With objRelationship
                .RelationshipID = CInt(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddRelationship"), .Relationship, .ViewOrder))
            End With
        End Sub

        Public Overrides Sub DeleteRelationship(ByVal RelationshipID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteRelationship"), RelationshipID)
        End Sub

        Public Overrides Sub UpdateRelationship(ByVal objRelationship As RelationshipInfo)
            With objRelationship
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateRelationship"), .RelationshipID, .Relationship, .ViewOrder)
            End With
        End Sub
#End Region

#Region "ChurchRelationships"
        Public Overrides Function GetChurchRelationships() As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetChurchRelationships")), IDataReader)
        End Function

        Public Overrides Function GetChurchRelationship(ByVal ChurchRelationshipID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetChurchRelationship"), ChurchRelationshipID), IDataReader)
        End Function

        Public Overrides Sub AddChurchRelationship(ByVal objChurchRelationship As ChurchRelationshipInfo)
            With objChurchRelationship
                .ChurchRelationshipID = CInt(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddChurchRelationship"), .ChurchRelationship, .ViewOrder))
            End With
        End Sub

        Public Overrides Sub DeleteChurchRelationship(ByVal ChurchRelationshipID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteChurchRelationship"), ChurchRelationshipID)
        End Sub

        Public Overrides Sub UpdateChurchRelationship(ByVal objChurchRelationship As ChurchRelationshipInfo)
            With objChurchRelationship
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateChurchRelationship"), .ChurchRelationshipID, .ChurchRelationship, .ViewOrder)
            End With
        End Sub
#End Region

#Region "Distributions"
        Public Overrides Function GetDistributions(ByVal ModuleID As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetDistributions"), Null.GetNull(ModuleID, DBNull.Value)), IDataReader)
        End Function

        Public Overrides Function GetDistribution(ByVal DistributionID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetDistribution"), DistributionID), IDataReader)
        End Function

        Public Overrides Sub AddDistribution(ByVal objDistribution As DistributionInfo)
            With objDistribution
                .DistributionID = CInt(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddDistribution"), .DistributionID, Null.GetNull(.ModuleID, DBNull.Value), .Distribution, .ViewOrder))
            End With
        End Sub

        Public Overrides Sub DeleteDistribution(ByVal DistributionID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteDistribution"), DistributionID)
        End Sub

        Public Overrides Sub UpdateDistribution(ByVal objDistribution As DistributionInfo)
            With objDistribution
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateDistribution"), .DistributionID, Null.GetNull(.ModuleID, DBNull.Value), .Distribution, .ViewOrder)
            End With
        End Sub
#End Region

#Region "Requests"
        Public Overrides Function GetRequests(ByVal ModuleID As Integer, ByVal Distributions As Integer, ByVal Filter As String, ByVal IncludeExpired As Boolean, ByVal OrderBy As String, ByVal UserID As Integer, ByVal PageSize As Integer, ByVal PageIndex As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetRequests"), ModuleID, Distributions, Filter, IncludeExpired, OrderBy, UserID, PageSize, PageIndex), IDataReader)
        End Function

        Public Overrides Function GetRequest(ByVal RequestID As Integer, ByVal UserId As Integer, ByVal HydrateUpdates As Boolean) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetRequest"), RequestID, UserId, HydrateUpdates), IDataReader)
        End Function

        Public Overrides Sub UpdateRequest(ByVal objRequest As RequestInfo)
            With objRequest
                Dim sc As SubjectContactInfo
                If .SubjectContact Is Nothing Then
                    sc = New SubjectContactInfo()
                Else
                    sc = .SubjectContact
                End If
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateRequest"), _
                      .RequestID, .IsPraise, .CategoryID, .Subject, GetNull(sc.Name), GetNull(sc.Address), GetNull(sc.City), _
                      GetNull(sc.State), GetNull(sc.ZipPlus4), GetNull(sc.EMail), .ChurchRelationshipID, _
                      .StatusID, GetNull(.Expires), .IsLocked)
            End With
        End Sub

        Public Overrides Sub UpdateRequestStatus(ByVal RequestID As Integer, ByVal StatusID As Integer, ByVal Expires As DateTime, ByVal IsLocked As Boolean)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateRequestStatus"), RequestID, StatusID, GetNull(Expires), IsLocked)
        End Sub

        Public Overrides Sub IncrementRequestViews(ByVal RequestID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("IncrementRequestViews"), RequestID)
        End Sub

        Public Overrides Function GetNewRequests(ByVal ModuleID As Integer, ByVal DaysForNew As Integer, ByVal MaxRows As Integer, ByVal UserID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetNewRequests"), ModuleID, DaysForNew, MaxRows, UserID), IDataReader)
        End Function

        Public Overrides Function GetExpiredRequests(ByVal ModuleID As Integer, ByVal Filter As String, ByVal OrderBy As String, ByVal UserID As Integer, ByVal PageSize As Integer, ByVal PageIndex As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetExpiredRequests"), ModuleID, Filter, OrderBy, UserID, PageSize, PageIndex), IDataReader)
        End Function

#End Region

#Region "Posts"
        Public Overrides Function GetPosts(ByVal RequestID As Integer, ByVal Distributions As Integer, ByVal GetOnlyUpdates As Boolean) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetPosts"), RequestID, Distributions, GetOnlyUpdates), IDataReader)
        End Function

        Public Overrides Function GetPost(ByVal PostID As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetPost"), PostID), IDataReader)
        End Function

        Public Overrides Function AddPost(ByVal objRequest As RequestInfo, ByVal objPost As PostInfo, _
                                          ByVal CreatedByUserID As Integer, ByVal CreatedOnDate As DateTime, ByVal LastModifiedByUserID As Integer, ByVal LastModifiedOnDate As DateTime) As Integer
            Dim Track As Object
            If objPost.Track = -1 Then
                Track = DBNull.Value
            Else
                Track = (objPost.Track = 1)
            End If
            Dim sc As SubjectContactInfo
            If objRequest.SubjectContact Is Nothing Then
                sc = New SubjectContactInfo()
            Else
                sc = objRequest.SubjectContact
            End If

            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddPost"), _
                                 objPost.Body, GetNull(objPost.SubmittedFor), objPost.RelationshipID, objPost.RemoteAddr, Track, _
                                 objPost.NotifySubject, objPost.Distribution, objRequest.RequestID, objRequest.ModuleID, objRequest.IsPraise, objRequest.CategoryID, _
                                 objRequest.Subject, GetNull(sc.Name), GetNull(sc.Address), GetNull(sc.City), GetNull(sc.State), GetNull(sc.ZipPlus4), _
                                 GetNull(sc.EMail), objRequest.ChurchRelationshipID, objRequest.StatusID, GetNull(objRequest.Expires), objRequest.IsLocked, CreatedByUserID, GetNull(CreatedOnDate), GetNull(LastModifiedByUserID), GetNull(LastModifiedOnDate)), Integer)
            Catch ex As Exception
                Return -1
            End Try
        End Function

        Public Overrides Sub UpdatePost(ByVal objPost As PostInfo, ByVal UserID As Integer)
            Dim Track As Object

            With objPost
                If .Track = -1 Then
                    Track = DBNull.Value
                Else
                    Track = (.Track = 1)
                End If

                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdatePost"), _
                .PostID, .Body, GetNull(.SubmittedFor), .RelationshipID, .RemoteAddr, Track, .NotifySubject, .Distribution, UserID)
            End With
        End Sub

        Public Overrides Sub DeletePost(ByVal PostID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeletePost"), PostID)
        End Sub

        Public Overrides Function GetNewUpdates(ByVal ModuleID As Integer, ByVal DaysForNew As Integer, ByVal MaxRows As Integer, ByVal UserID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetNewUpdates"), ModuleID, DaysForNew, MaxRows, UserID), IDataReader)
        End Function

        Public Overrides Function GetMyPosts(ByVal ModuleID As Integer, ByVal UserID As Integer, ByVal OrderBy As String, ByVal PageSize As Integer, ByVal PageIndex As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetMyPosts"), ModuleID, UserID, OrderBy, PageSize, PageIndex), IDataReader)
        End Function

        Public Overrides Sub ClearNotifySubject(ByVal PostID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("ClearNotifySubject"), PostID)
        End Sub

#End Region

#Region "Moderators"
        Public Overrides Function IsModerator(ByVal ModuleID As Integer, ByVal UserID As Integer) As Boolean
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("IsModerator"), ModuleID, UserID), Boolean)
        End Function

        Public Overrides Function GetModerator(ByVal ModuleID As Integer, ByVal UserID As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetModerator"), ModuleID, UserID), IDataReader)
        End Function

        Public Overrides Function GetModerators(ByVal ModuleID As Integer, ByVal GetActiveOnly As Boolean) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetModerators"), ModuleID, GetActiveOnly), IDataReader)
        End Function

        Public Overrides Sub AddModerator(ByVal ModuleID As Integer, ByVal UserID As Integer, ByVal ExpiresDate As DateTime)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("AddModerator"), ModuleID, UserID, GetNull(ExpiresDate))
        End Sub

        Public Overrides Sub UpdateModerator(ByVal ModuleID As Integer, ByVal UserID As Integer, ByVal ExpiresDate As DateTime, ByVal IsSuspended As Boolean)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateModerator"), ModuleID, UserID, GetNull(ExpiresDate), IsSuspended)
        End Sub

        Public Overrides Sub DeleteModerator(ByVal ModuleId As Integer, ByVal UserID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteModerator"), ModuleId, UserID)
        End Sub

        Public Overrides Function GetModeratorEmails(ByVal PostID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetModeratorEmails"), PostID), IDataReader)
        End Function

#End Region

#Region "Moderation"
        Public Overrides Function GetPostsToModerate(ByVal ModuleID As Integer) As System.Data.IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetPostsToModerate"), ModuleID), IDataReader)
        End Function

        Public Overrides Sub ModerateApprovePost(ByVal PostID As Integer, ByVal ApprovedBy As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("ModerateApprovePost"), PostID, ApprovedBy)
        End Sub

        Public Overrides Sub ModerateRejectPost(ByVal PostID As Integer, ByVal RejectedBy As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("ModerateRejectPost"), PostID, RejectedBy)
        End Sub

        Public Overrides Sub ModerateUnapprovePost(ByVal PostID As Integer, ByVal UnapprovedBy As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("ModerateUnapprovePost"), PostID, UnapprovedBy)
        End Sub
#End Region

#Region "Users"

        Public Overrides Sub IncrementUserVisits(ByVal ModuleID As Integer, ByVal UserID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("IncrementUserVisits"), ModuleID, UserID)
        End Sub

        Public Overrides Function GetUsers(ByVal ModuleId As Integer, ByVal Filter As String, ByVal OrderBy As String, _
                                           ByVal PageSize As Integer, ByVal PageIndex As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetUsers"), ModuleId, Filter, OrderBy, _
                     PageSize, PageIndex), IDataReader)
        End Function

        Public Overrides Function GetUser(ByVal ModuleId As Integer, ByVal UserID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetUser"), ModuleId, UserID), IDataReader)
        End Function

        Public Overrides Function GetUser(ByVal ModuleId As Integer, ByVal [Alias] As String) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetUserByAlias"), ModuleId, [Alias]), IDataReader)
        End Function

        Public Overrides Sub AddUser(ByVal ModuleId As Integer, ByVal UserID As Integer, ByVal [Alias] As String, ByVal PageSize As Integer, ByVal OrderBy As String, ByVal MailFormat As DotNetNuke.Services.Mail.MailFormat, ByVal ViewableDistributions As Integer, ByVal IsTrusted As Boolean)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("AddUser"), ModuleId, UserID, GetNull([Alias]), PageSize, OrderBy, CType(MailFormat, Integer), ViewableDistributions, IsTrusted)
        End Sub

        Public Overrides Sub UpdateUser(ByVal objUser As UserInfo)
            With objUser
                SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateUser"), .ModuleID, .UserID, GetNull(.Alias), .IdentifyBy, GetNull(.Signature), .PageSize, .OrderBy, CType(.MailFormat, Integer), .ViewableDistributions, .IsTrusted, .IsBanned, GetNull(.BannedUntilDate))
            End With
        End Sub

        Public Overrides Sub DeleteUser(ByVal ModuleId As Integer, ByVal UserID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("DeleteUser"), ModuleId, UserID)
        End Sub

#End Region

#Region "Tracking"
        Public Overrides Function GetTrackingEmails(ByVal PostID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetTrackingEmails"), PostID), IDataReader)
        End Function

        Public Overrides Sub StartEndAllPostsTracking(ByVal ModuleID As Integer, ByVal UserID As Integer, ByVal Start As Boolean)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("StartEndAllPostsTracking"), ModuleID, UserID, Start)
        End Sub

        Public Overrides Sub StartEndRequestTracking(ByVal RequestID As Integer, ByVal UserID As Integer, ByVal Start As Boolean)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("StartEndRequestTracking"), RequestID, UserID, Start)
        End Sub
#End Region

#Region "MasterModules and Agregators"
        Public Overrides Function GetAvailableMasterModules(ByVal PortalID As Integer, ByVal AgregatorModuleID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetAvailableMasterModules"), PortalID, AgregatorModuleID), IDataReader)
        End Function

        Public Overrides Sub SaveAgregators(ByVal AgregatorModuleID As Integer, ByVal MasterModuleIds As String)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("SaveAgregators"), AgregatorModuleID, MasterModuleIds)
        End Sub
#End Region

#Region "Stats"
        Public Overrides Sub InitializeStats(ByVal ModuleID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("InitializeStats"), ModuleID)
        End Sub

        Public Overrides Function GetStats(ByVal ModuleID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetStats"), ModuleID), IDataReader)
        End Function

        Public Overrides Sub RefreshStats(ByVal ModuleID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("RefreshStats"), ModuleID)
        End Sub

        Public Overrides Sub UpdateStats(ByVal ModuleID As Integer, ByVal Requests As Integer, ByVal Updates As Integer, _
                                              ByVal MostRecentRequestID As Integer, ByVal MostRecentPostID As Integer, _
                                              ByVal MostRecentAuthorID As Integer, ByVal MostRecentPostDate As DateTime, _
                                              ByVal PostsToModerate As Integer)

            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpdateStats"), ModuleID, Requests, Updates, _
                  GetNull(MostRecentRequestID), GetNull(MostRecentPostID), GetNull(MostRecentAuthorID), GetNull(MostRecentPostDate), PostsToModerate)
        End Sub

        Public Overrides Sub UpgradeStats(ByVal ModuleID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, GetFullyQualifiedName("UpgradeStats"), ModuleID)
        End Sub

#End Region

#End Region

    End Class

End Namespace